-- this is how to get pcall to return false
code, err = pcall(error, "some error code")
print('pcall(error, "some error code") --> ', code, err)

-- in this invocation, pcall(error, "...") is called,
-- returning false and "...", but since the invocation
-- is wrapped in another pcall, the whole thing returns
-- true (since the inner pcall doesn't raise an error),
-- false (since the inner pcall catches an error) and
-- "...", the error string
outer, inner, err = pcall(pcall, error, "some error code")
print('pcall(pcall, error, "some error code") --> ', outer, inner, err)
function f ()
  count = 0
  -- the hook function
  function g ()
    count = count + 1
    -- unset the hook function, otherwise when the outer pcall
    -- returns, there will be an error, and print wont't receive
    -- the result.
    -- raise an error
    if count == 2 then debug.sethook() end
    error()
  end
  -- run when a function returns
  debug.sethook(g, "r")
end

print(pcall(pcall, f))